<script type="text/javascript">
  {% if raw_code then %}
  function random_sign(randomkey, value) {
    var j = 0;
    var sign = [];
    randomkey = randomkey.split("").reverse().join("");
    for (i = 0; i < value.length; i++) {
      sign[i] = value[i].charCodeAt() ^ randomkey[i % randomkey.length].charCodeAt() & 0xff;
      sign[i] = sign[i] < 16 && "0" + sign[i].toString(16) || sign[i].toString(16);
    }
    return sign.join("");
  }
  {% else %}
  window["\x65\x76\x61\x6c"](function($$DP1,bIdHTa2,XDkj3,IrMHsICt4,YIv5,BzXiP6){YIv5=function(XDkj3){return(XDkj3<bIdHTa2?"":YIv5(window["\x70\x61\x72\x73\x65\x49\x6e\x74"](XDkj3/bIdHTa2)))+((XDkj3=XDkj3%bIdHTa2)>35?window["\x53\x74\x72\x69\x6e\x67"]["\x66\x72\x6f\x6d\x43\x68\x61\x72\x43\x6f\x64\x65"](XDkj3+29):XDkj3["\x74\x6f\x53\x74\x72\x69\x6e\x67"](36))};if(!''["\x72\x65\x70\x6c\x61\x63\x65"](/^/,window["\x53\x74\x72\x69\x6e\x67"])){while(XDkj3--)BzXiP6[YIv5(XDkj3)]=IrMHsICt4[XDkj3]||YIv5(XDkj3);IrMHsICt4=[function(YIv5){return BzXiP6[YIv5]}];YIv5=function(){return'\\\x77\x2b'};XDkj3=1;};while(XDkj3--)if(IrMHsICt4[XDkj3])$$DP1=$$DP1["\x72\x65\x70\x6c\x61\x63\x65"](new window["\x52\x65\x67\x45\x78\x70"]('\\\x62'+YIv5(XDkj3)+'\\\x62','\x67'),IrMHsICt4[XDkj3]);return $$DP1;}('\x62 \x63\x28\x32\x2c\x34\x29\x7b\x37 \x64\x3d\x30\x3b\x37 \x31\x3d\x5b\x5d\x3b\x32\x3d\x32\x2e\x61\x28\x22\x22\x29\x2e\x65\x28\x29\x2e\x39\x28\x22\x22\x29\x3b\x68\x28\x69\x3d\x30\x3b\x69\x3c\x34\x2e\x36\x3b\x69\x2b\x2b\x29\x7b\x31\x5b\x69\x5d\x3d\x34\x5b\x69\x5d\x2e\x35\x28\x29\x5e\x32\x5b\x69\x25\x32\x2e\x36\x5d\x2e\x35\x28\x29\x26\x66\x3b\x31\x5b\x69\x5d\x3d\x31\x5b\x69\x5d\x3c\x33\x26\x26\x22\x30\x22\x2b\x31\x5b\x69\x5d\x2e\x38\x28\x33\x29\x7c\x7c\x31\x5b\x69\x5d\x2e\x38\x28\x33\x29\x7d\x67 \x31\x2e\x39\x28\x22\x22\x29\x7d',19,19,'\x7c\x73\x69\x67\x6e\x7c\x72\x61\x6e\x64\x6f\x6d\x6b\x65\x79\x7c\x31\x36\x7c\x76\x61\x6c\x75\x65\x7c\x63\x68\x61\x72\x43\x6f\x64\x65\x41\x74\x7c\x6c\x65\x6e\x67\x74\x68\x7c\x76\x61\x72\x7c\x74\x6f\x53\x74\x72\x69\x6e\x67\x7c\x6a\x6f\x69\x6e\x7c\x73\x70\x6c\x69\x74\x7c\x66\x75\x6e\x63\x74\x69\x6f\x6e\x7c\x72\x61\x6e\x64\x6f\x6d\x5f\x73\x69\x67\x6e\x7c\x6a\x7c\x72\x65\x76\x65\x72\x73\x65\x7c\x30\x78\x66\x66\x7c\x72\x65\x74\x75\x72\x6e\x7c\x66\x6f\x72\x7c'["\x73\x70\x6c\x69\x74"]('\x7c'),0,{}))
  {% end %}
</script>

<script>
  layui.config({base: '{*cdn*}layui_ext/dist/'}).use(['form', 'jquery', 'sliderVerify'], function(){
    var $ = layui.$;
    var form = layui.form;

    var slider = layui.sliderVerify.render({elem: '#slider'});
    //监听提交
    form.on('submit(login)', function(data){
      // 判断登录按钮是否隐藏, 隐藏之后不允许重复提交登录.
      if (!$('#sub').is(":hidden")) {
        if (slider.isOk()){
          data.field.verify_code = random_sign(data.field.randomkey, data.field.username + data.field.password);
        }
        $('#sub').hide();
        $.ajax({
          url: "{*login_api*}", type: "POST", data: data.field,
          success: function (res) {
            if (res.code != 0){
              // 登录失败
              return layer.msg(res.msg, {time: 2000},  function(){
                return slider.reset(), $('#sub').show();
              });
            }
            // 登录成功
            return layer.msg(res.msg, {time: 1000}, function(){return location.href = res.url + '?token=' + res.token; });
          },
          error: function(res) { // 网络请求失败
            return layer.msg("网络连接失败", {time: 2000}, function(){
              return slider.reset(), $('#sub').show();
            });
          },
        })
      }
      return false;
    });
  });

  if (self && top && self != top) {
    parent.window.location.reload();
  }
</script>